package com.task.web.controller.core;

import javax.annotation.Resource;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.task.common.annotation.Log;
import com.task.common.core.controller.BaseController;
import com.task.common.core.domain.AjaxResult;
import com.task.common.core.page.TableDataInfo;
import com.task.common.enums.BusinessType;
import com.task.common.utils.SecurityUtils;
import com.task.core.dto.request.DeviceFraudPlatformRequestDTO;
import com.task.core.dto.request.DeviceFraudRequestDTO;
import com.task.core.service.CheckService;
import com.task.core.service.DeviceFraudPlatformService;
import com.task.core.service.DeviceFraudService;

import io.swagger.annotations.Api;

/**
 * @author 迪迦.
 * @date 2024/11/4 14:29
 */
@Api("")
@RestController
@RequestMapping("/deviceFraudPlatform")
public class DeviceFraudPlatformController extends BaseController {


  @Resource
  private DeviceFraudPlatformService deviceFraudPlatformService;

  @Resource
  private CheckService checkService;


  @PreAuthorize("@ss.hasPermi('deviceFraudPlatform:list')")
  @GetMapping("/getDeviceFraudPlatformByPage")
  public TableDataInfo getDeviceFraudPlatformByPage(DeviceFraudPlatformRequestDTO request) {
    startPage(request.getPageNum(), request.getPageSize());
    return getDataTable(deviceFraudPlatformService.getDeviceFraudPlatformByPage(request));
  }


  @PreAuthorize("@ss.hasPermi('deviceFraudPlatform:option')")
  @GetMapping("/getDeviceFraudPlatformForOption")
  public TableDataInfo getDeviceFraudPlatformForOption(DeviceFraudPlatformRequestDTO request) {
    return getDataTable(deviceFraudPlatformService.getDeviceFraudPlatformForOption(request));
  }

  @Log(title = "DeviceFraudPlatform管理", businessType = BusinessType.INSERT)
  @PostMapping("/addDeviceFraudPlatform")
  public AjaxResult addDeviceFraudPlatform(@Validated @RequestBody DeviceFraudPlatformRequestDTO request) {
    request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
    deviceFraudPlatformService.addDeviceFraudPlatform(request);
    return success();
  }

  @Log(title = "DeviceFraudPlatform管理", businessType = BusinessType.UPDATE)
  @PutMapping("/modifyDeviceFraudPlatform")
  public AjaxResult modifyDeviceFraudPlatform(@Validated @RequestBody DeviceFraudPlatformRequestDTO request) {
    checkService.check("data_device_fraud_platform", request.getCode());
    request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
    deviceFraudPlatformService.modifyDeviceFraudPlatform(request);
    return success();
  }

  @Log(title = "DeviceFraudPlatform管理", businessType = BusinessType.DELETE)
  @DeleteMapping("/deleteDeviceFraudPlatform/{deviceFraudPlatformCode}")
  public AjaxResult deleteDeviceFraudPlatform(@PathVariable String deviceFraudPlatformCode) {
    checkService.check("data_device_fraud_platform", deviceFraudPlatformCode);
    deviceFraudPlatformService.deleteDeviceFraudPlatform(deviceFraudPlatformCode, SecurityUtils.getLoginUser().getUserId());
    return success();
  }


}
